#!/usr/bin/env bash

sudo mariadb <<EOF
create user dbuser@'%' identified by 'dbuser';
create user dbuser@localhost identified by 'dbuser';

create database soar_template_springboot_main charset utf8 collate utf8_bin;
grant select,insert,update,delete,create,drop,index,alter on soar_template_springboot_main.* to dbuser;
grant select,insert,update,delete,create,drop,index,alter on soar_template_springboot_main.* to dbuser@localhost;
grant lock tables on soar_template_springboot_main.* to dbuser;
grant lock tables on soar_template_springboot_main.* to dbuser@localhost;

create database soar_template_springboot_log charset utf8 collate utf8_bin;
grant select,insert,update,delete,create,drop,index,alter on soar_template_springboot_log.* to dbuser;
grant select,insert,update,delete,create,drop,index,alter on soar_template_springboot_log.* to dbuser@localhost;
grant lock tables on soar_template_springboot_log.* to dbuser;
grant lock tables on soar_template_springboot_log.* to dbuser@localhost;
EOF

mysql -udbuser -pdbuser soar_template_springboot_main <<EOF
source main/user_info.sql;
EOF

mysql -udbuser -pdbuser soar_template_springboot_log <<EOF
source log/user_log.sql;
EOF
